package jmine.tec.script.persistent.pack;

import static jmine.tec.database.pack.PackingMessages.IO_EXCEPTION;

import java.io.IOException;
import java.io.OutputStream;

import jmine.tec.database.pack.PackException;
import jmine.tec.database.pack.populator.AbstractPopulatorWriterSource;
import jmine.tec.script.persistent.domain.Script;

import org.apache.commons.io.IOUtils;

/**
 * @author lundberg
 */
public class ScriptPopulatorWriter extends AbstractPopulatorWriterSource<Script> {

    /**
     * {@inheritDoc}
     */
    public void write(Script script, OutputStream output) throws PackException {
        try {
            IOUtils.write(script.getBody(), output, "UTF-8");
        } catch (IOException e) {
            throw new PackException(IO_EXCEPTION, e);
        }
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "ScriptPopulatorWriter";
    }
}
